import React, { Component } from 'react'

export default class Demo extends Component {

  state = {count:0}

  increment = ()=>{
    // 1.对象式的setState
    // const {count} = this.state
    // this.setState({count:count+1},()=>{
    //   console.log('状态更新完毕,界面更新后(render函数调用后)',this.state.count);
    // })

    // 2.函数式的setState
    // this.setState((state,props)=>{
    //   console.log(state,props);//{count: 0} {x: 66}
    //   return {count:state.count+1}
    // },()=>{})
    // this.setState(state=>({count:state.count+1}))
  }

  render() {
    return (
      <div>
        <h2>当前求和为:{this.state.count}</h2>
        <button onClick={this.increment}>点我加1</button>
      </div>
    )
  }
}
